package com.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.service.Impl.UsersServiceImpl;
import com.service.UsersService;

@WebServlet("/checkedName")
public class checkedName extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
        //获取登录框数据
        String username = request.getParameter("username");
        //获取登录用户存在库中的信息
        UsersService  usersService = new UsersServiceImpl();
        boolean stage = usersService.findName(username);
        System.out.println(stage);
        //判断用户名是否存在于库中
        response.setContentType("text/html;charset=utf-8");
        if(stage == true) {
            response.getWriter().write("<font style='color:green'> 用户名可用~</font> ");
        }else {
            response.getWriter().write("<font style='color:red'> 用户名不可用~</font> ");
        }
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
}
